package cn.iocoder.yudao.framework.magic.config.function;

import org.springframework.stereotype.Component;
import org.ssssssss.magicapi.core.config.MagicFunction;
import org.ssssssss.script.annotation.Comment;
import org.ssssssss.script.annotation.Function;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;

public class LocalDateTimeFunction implements MagicFunction {

    @Function
    @Comment("时间戳转时间(LocalDateTime)")
    public static LocalDateTime timeStampParseLocalDateTime(Long timestamp) {
        return LocalDateTime.ofInstant(Instant.ofEpochSecond(timestamp), ZoneId.systemDefault());
    }


    @Function
    @Comment("时间转时间戳(LocalDateTime)")
    public static long localDateParseTimeTimeStamp(LocalDateTime localDateTime) {
        ZoneId zone = ZoneId.systemDefault();
        Instant instant = localDateTime.atZone(zone).toInstant();
        return instant.getEpochSecond();
    }




}
